package com.endoc.news.fragment.base;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public  class BaseObserver<T> implements Observer<T> {
    BaseMvvmModel baseModel;
    MvvmDataObserver<T> mvvmDataObserver;

    public BaseObserver(BaseMvvmModel baseModel, MvvmDataObserver<T> mvvmDataObserver) {
        this.baseModel = baseModel;
        this.mvvmDataObserver = mvvmDataObserver;
    }


    @Override
    public void onSubscribe(Disposable d) {
        //存储本次订阅,方便以后想取消的时候取消
        if(baseModel!=null){
            baseModel.addDisposable(d);
        }
    }

    @Override
    public void onNext(T t) {
        mvvmDataObserver.onSuccess(t,false);
        //success(t);
    }

    @Override
    public void onError(Throwable e) {
        mvvmDataObserver.onFailure(e);
        //fail(e);
    }

    @Override
    public void onComplete() {

    }

   /* public abstract void success(T t);
    public abstract void fail(Throwable e);*/
}
